//
//  HNSH_GoodsSpecModel.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/25.
//

#import "HNSH_GoodsSpecModel.h"

@implementation HNSH_GoodsSpecModel

+ (NSDictionary *)modelContainerPropertyGenericClass{
    return @{
             @"spec_list":HNSH_GoodsSpecListItem.class,
             @"attribute_list":HNSH_GoodsSpecAttributeListItem.class
            };
}

/** 通过所选择的规格查找到想要的规格 */
- (HNSH_GoodsSpecListItem *)getCurrentItemModel {
    NSArray * att_list = self.attribute_list;
    NSString * key = nil;
    for (HNSH_GoodsSpecAttributeListItem * attM in att_list) {
        for (HNSH_GoodsSpecAttributeItem * subM in attM.items) {
            if (subM.isSelected) {
                if (key) {
                    key = [NSString stringWithFormat:@"%@_%@", key, subM.uid];
                } else {
                    key = subM.uid;
                }
            }
        }
    }
    NSArray * spec_list = self.spec_list;
    for (HNSH_GoodsSpecListItem * iM in spec_list) {
        if ([iM.spec_key isEqualToString:key]) {
            self.currentItem = iM;
            return iM;
        }
    }
    return nil;
}

@end

@implementation HNSH_GoodsSpecAttributeItem

+ (NSDictionary *)modelCustomPropertyMapper{
    return @{@"uid":@"id"};
}

@end


@implementation HNSH_GoodsSpecAttributeListItem

+ (NSDictionary *)modelCustomPropertyMapper{
    return @{@"uid":@"id"};
}

+ (NSDictionary *)modelContainerPropertyGenericClass{
    return @{
             @"items":HNSH_GoodsSpecAttributeItem.class
            };
}

@end

@implementation HNSH_GoodsSpecListItem

+ (NSDictionary *)modelCustomPropertyMapper{
    return @{@"uid":@"id"};
}

@end


